home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / regcode / regsampl.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-08-11  |  8.7 KB  |  256 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "ECLIPSE Registry Demo"
  4.    ClientHeight    =   2685
  5.    ClientLeft      =   45
  6.    ClientTop       =   330
  7.    ClientWidth     =   5595
  8.    LinkTopic       =   "Form1"
  9.    LockControls    =   -1  'True
  10.    ScaleHeight     =   2685
  11.    ScaleWidth      =   5595
  12.    StartUpPosition =   2  'CenterScreen
  13.    Begin VB.TextBox txtAppKeyName 
  14.       Height          =   288
  15.       Left            =   1375
  16.       TabIndex        =   9
  17.       Text            =   "Text1"
  18.       Top             =   100
  19.       Width           =   4140
  20.    End
  21.    Begin VB.CommandButton cmdExit 
  22.       Caption         =   "E&xit"
  23.       Height          =   320
  24.       Left            =   4320
  25.       TabIndex        =   8
  26.       Top             =   2275
  27.       Width           =   1200
  28.    End
  29.    Begin VB.Frame Frame1 
  30.       Height          =   1716
  31.       Left            =   96
  32.       TabIndex        =   1
  33.       Top             =   456
  34.       Width           =   5412
  35.       Begin VB.CommandButton cmdReg 
  36.          Caption         =   "Delete Key"
  37.          Height          =   320
  38.          Index           =   2
  39.          Left            =   4000
  40.          TabIndex        =   13
  41.          Top             =   900
  42.          Width           =   1200
  43.       End
  44.       Begin VB.CommandButton cmdReg 
  45.          Caption         =   "Delete Value"
  46.          Height          =   320
  47.          Index           =   3
  48.          Left            =   4000
  49.          TabIndex        =   12
  50.          Top             =   1250
  51.          Width           =   1200
  52.       End
  53.       Begin VB.OptionButton optRegType 
  54.          Caption         =   "SZ (string)"
  55.          Height          =   204
  56.          Index           =   1
  57.          Left            =   2200
  58.          TabIndex        =   11
  59.          Top             =   850
  60.          Value           =   -1  'True
  61.          Width           =   1605
  62.       End
  63.       Begin VB.OptionButton optRegType 
  64.          Caption         =   "DWORD (numbers)"
  65.          Height          =   204
  66.          Index           =   0
  67.          Left            =   100
  68.          TabIndex        =   10
  69.          Top             =   850
  70.          Width           =   2085
  71.       End
  72.       Begin VB.CommandButton cmdReg 
  73.          Caption         =   "Query Value"
  74.          Height          =   320
  75.          Index           =   1
  76.          Left            =   4000
  77.          TabIndex        =   7
  78.          Top             =   550
  79.          Width           =   1200
  80.       End
  81.       Begin VB.CommandButton cmdReg 
  82.          Caption         =   "Store Value"
  83.          Height          =   320
  84.          Index           =   0
  85.          Left            =   4000
  86.          TabIndex        =   6
  87.          Top             =   200
  88.          Width           =   1200
  89.       End
  90.       Begin VB.TextBox txtKeyValue 
  91.          Height          =   288
  92.          Left            =   1020
  93.          TabIndex        =   5
  94.          Text            =   "Text1"
  95.          Top             =   1152
  96.          Width           =   2000
  97.       End
  98.       Begin VB.TextBox txtKeyName 
  99.          Height          =   288
  100.          Left            =   1000
  101.          TabIndex        =   4
  102.          Text            =   "Text1"
  103.          Top             =   225
  104.          Width           =   2000
  105.       End
  106.       Begin VB.Label Label1 
  107.          Caption         =   "Key Value :"
  108.          Height          =   192
  109.          Index           =   2
  110.          Left            =   120
  111.          TabIndex        =   3
  112.          Top             =   1200
  113.          Width           =   804
  114.       End
  115.       Begin VB.Label Label1 
  116.          Caption         =   "Key Name :"
  117.          Height          =   192
  118.          Index           =   1
  119.          Left            =   96
  120.          TabIndex        =   2
  121.          Top             =   252
  122.          Width           =   828
  123.       End
  124.    End
  125.    Begin VB.Label Label1 
  126.       Caption         =   "Registry Success :"
  127.       Height          =   192
  128.       Index           =   3
  129.       Left            =   144
  130.       TabIndex        =   15
  131.       Top             =   2280
  132.       Width           =   1332
  133.    End
  134.    Begin VB.Label lblSuccess 
  135.       AutoSize        =   -1  'True
  136.       Caption         =   "_"
  137.       Height          =   195
  138.       Left            =   1635
  139.       TabIndex        =   14
  140.       Top             =   2280
  141.       Width           =   90
  142.    End
  143.    Begin VB.Label Label1 
  144.       Caption         =   "Application Key :"
  145.       Height          =   192
  146.       Index           =   0
  147.       Left            =   120
  148.       TabIndex        =   0
  149.       Top             =   120
  150.       Width           =   1188
  151.    End
  152. Attribute VB_Name = "Form1"
  153. Attribute VB_GlobalNameSpace = False
  154. Attribute VB_Creatable = False
  155. Attribute VB_PredeclaredId = True
  156. Attribute VB_Exposed = False
  157. Option Explicit
  158. Private Sub cmdExit_Click()
  159.     Unload Me
  160. End Sub
  161. Private Sub cmdReg_Click(Index As Integer)
  162. Dim result
  163. Dim KeyResult
  164.     If txtKeyName.Text = "" Then
  165.         ' Warn if no Key Name to create
  166.         MsgBox "KeyName not specified!", vbCritical
  167.         Exit Sub
  168.     End If
  169.     If txtKeyValue.Text = "" And (Index = 0 Or Index = 3) Then
  170.         ' Warn if no Value to store. Won't succeed anyway
  171.         result = MsgBox("No Value to store/delete. Proceed Anyway?", vbInformation Or vbYesNo)
  172.         If result = vbNo Then Exit Sub
  173.     End If
  174.     Select Case Index
  175.         Case 0
  176.             ' Creates the key specified in the txtKeyName textbox
  177.             ' and stores the value specified in the txtKeyValue textbox
  178.             If optRegType(0).Value Then
  179.                 ' Stores a REG_DWORD type value
  180.                 result = SetRegValue(HKEY_LOCAL_MACHINE, txtAppKeyName.Text, txtKeyName.Text, REG_DWORD, txtKeyValue.Text)
  181.             Else
  182.                 ' Stores a REG_SZ type value
  183.                 result = SetRegValue(HKEY_LOCAL_MACHINE, txtAppKeyName.Text, txtKeyName.Text, REG_SZ, txtKeyValue.Text)
  184.             End If
  185.         Case 1
  186.             ' Retrieves the value of the name specified in the
  187.             ' txtKeyName textbox and assign it to the txtKeyValue textbox
  188.             If optRegType(0).Value Then
  189.                 ' Retrieves a REG_DWORD type value
  190.                 result = GetRegValue(HKEY_LOCAL_MACHINE, txtAppKeyName.Text, txtKeyName.Text, REG_DWORD, KeyResult)
  191.                 txtKeyValue.Text = regValue 'KeyResult
  192.             Else
  193.                 ' Retrieves a REG_SZ type value
  194.                 result = GetRegValue(HKEY_LOCAL_MACHINE, txtAppKeyName.Text, txtKeyName.Text, REG_SZ, KeyResult)
  195.                 txtKeyValue.Text = regValue 'KeyResult
  196.             End If
  197.         Case 2
  198.             ' Delete an entire key. Use with CAUTION when you've change the values
  199.             result = DeleteRegEntry(HKEY_LOCAL_MACHINE, txtAppKeyName.Text)
  200.             txtKeyValue.Text = ""
  201.         Case 3
  202.             ' Delete a key. Use with CAUTION when you've change the values
  203.             result = DeleteRegValue(HKEY_LOCAL_MACHINE, txtAppKeyName.Text, txtKeyName.Text)
  204.             txtKeyValue.Text = ""
  205.     End Select
  206.     ' show result in lblSuccess control, either True or False
  207.     If result Then
  208.         lblSuccess.ForeColor = vbBlue
  209.     Else
  210.         lblSuccess.ForeColor = vbRed
  211.     End If
  212.     lblSuccess.Caption = result
  213. End Sub
  214. Private Sub Form_Load()
  215. Dim result
  216.     txtAppKeyName.Text = regAppKeyName
  217.     lblSuccess.Caption = ""
  218.     ' Check if a certain key exist
  219.     ' regAppKeyName = "Software\ECLIPSE Development Software\" & regAppName
  220.     result = regKeyExist(HKEY_LOCAL_MACHINE, regAppKeyName)
  221.     If Not result Then
  222.         ' Creates the key if it doesn't exist.
  223.         ' This key will be deleted when you end this project
  224.         CreateRegEntry HKEY_LOCAL_MACHINE, regAppKeyName
  225.     End If
  226.     ' default key to write in the registry.
  227.     ' This can be modified by changing the value
  228.     ' specified in the txtKeyName and txtKeyValue controls.
  229.     txtKeyName.Text = "RegDemo"
  230.     txtKeyValue.Text = "Sample Value to store"
  231. '    result = Val("XXX")
  232. End Sub
  233. Private Sub Form_Unload(Cancel As Integer)
  234. Dim result
  235.     ' Checks if a certain key exist.
  236.     result = regKeyExist(HKEY_LOCAL_MACHINE, regAppKeyName)
  237.     If result Then
  238.         ' Clean up the registry by deleting only the
  239.         ' keys and values we stored.
  240.         DeleteRegEntry HKEY_LOCAL_MACHINE, regAppKeyName
  241.     End If
  242. End Sub
  243. Private Sub optRegType_Click(Index As Integer)
  244.     txtKeyValue.Text = ""
  245. End Sub
  246. Private Sub txtKeyValue_Change()
  247.     lblSuccess.Caption = ""
  248. End Sub
  249. Private Sub txtKeyValue_KeyPress(KeyAscii As Integer)
  250.     ' if option is REG_DWORD, limit input to numbers only
  251.     ' otherwise, accept anything.
  252.     If optRegType(0).Value Then
  253.         If KeyAscii > 57 Then KeyAscii = 0
  254.     End If
  255. End Sub
  256.